home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / GE_VSRC.ZIP / VEC.ASM < prev    next >
Assembly Source File  |  1995-04-15  |  5KB  |  215 lines

  1. DISTANCE equ 8                         ;log 2 of Distance from eye to screen
  2.                                           
  3.         .386p
  4. code32  segment para public use32
  5.         assume cs:code32, ds:code32
  6.  
  7. include pmode.inc
  8.  
  9. ideal
  10. public _CreateRotateMatrix, _XformPts, _Cos, _Sin, _DotProduct
  11.  
  12. even
  13. include 'sintab.inc'
  14.  
  15. ; Rotation function, spherical coordinates.  Uses 4 multiplies.
  16. ; AX = Theta, BX = Phi, ECX = p, ESI -> 4x4 matrix
  17. ; ESI updated as follows--
  18. ; -sinΘ  -cosΘcosφ  -cosΘsinφ  0 
  19. ;  cosΘ  -sinΘcosφ  -sinΘsinφ  0 
  20. ;  0      sinφ      -cosφ      0 
  21. ;  0      0          p         1 
  22.  
  23. _CreateRotateMatrix:
  24.     pushad
  25.     mov [esi+14*4],ecx                ;set rho   [2][3]
  26.     
  27.     call _Sin                         ;After sin/cos calls,
  28.     mov edi,edx                       ;EDI = Sin Theta
  29.     call _Cos                         ;EBP = Cos Theta
  30.     mov ebp,edx                       ;EBX = Sin Phi
  31.     mov ax,bx                         ;ECX = Cos Phi
  32.     call _Sin
  33.     mov ebx,edx
  34.     call _Cos
  35.     mov ecx,edx
  36.     
  37.     neg edi
  38.     mov [esi],edi                     ;-sinT   [0][0]
  39.  
  40.     mov eax,edi
  41.     imul ecx                          ;-sinTcosP [1][1]
  42.     shrd eax,edx,16                   ;fixed point mul - get it back 
  43.     mov [esi+5*4],eax                 ;into 16.16 format.
  44.  
  45.     mov eax,edi                       ;-sinTsinP [2][1]
  46.     imul ebx
  47.     shrd eax,edx,16
  48.     mov [esi+6*4],eax
  49.     
  50.     mov [esi+4*4],ebp                 ;cosT [0][1]
  51.     
  52.     neg ebp                           ;-cosTcosP [1][0]
  53.     mov eax,ebp
  54.     imul ecx
  55.     shrd eax,edx,16
  56.     mov [esi+1*4],eax
  57.     
  58.     mov eax,ebp                       ;-cosTsinP [2][0]
  59.     imul ebx
  60.     shrd eax,edx,16
  61.     mov [esi+2*4],eax
  62.     
  63.     mov [esi+9*4],ebx                 ;sinP [1][2]
  64.     
  65.     neg ecx                           ;-cosP [2][2]
  66.     mov [esi+10*4],ecx
  67.     
  68.     popad
  69.     ret
  70.     
  71. ;Transform list of points.
  72. ;ESI->X,Y,Z triplets
  73. ;EDI->X,Y list to be filled (words)
  74. ;CX = number of points to process
  75. ;EBX->rotation matrix
  76.  
  77. even
  78. XTemp dd ?
  79. YTemp dd ?
  80. ZTemp dd ?
  81. NewX  dd ?
  82. NewY  dd ?
  83.  
  84. _XformPts:
  85.     push cx
  86.     
  87.     lodsd                             ;matrix multiply stuff.
  88.     mov [XTemp],eax                   ;this is intentionally left 
  89.     imul [dword ebx]                  ;without the obvious loop.
  90.     shrd eax,edx,16
  91.     mov ecx,eax                       ;calc NewX in cx
  92.     lodsd
  93.     mov [YTemp],eax
  94.     imul [dword ebx+4*4]
  95.     shrd eax,edx,16
  96.     add ecx,eax
  97.     lodsd
  98.     mov [ZTemp],eax
  99.     imul [dword ebx+8*4]
  100.     shrd eax,edx,16
  101.     add ecx,eax
  102.     add ecx,[ebx+12*4]                ;xtranslate
  103.     mov [NewX],ecx
  104.     
  105.     mov eax,[XTemp]                   ;calc NewY
  106.     imul [dword ebx+1*4]                          
  107.     shrd eax,edx,16
  108.     mov ecx,eax                       
  109.     mov eax,[YTemp]
  110.     imul [dword ebx+5*4]
  111.     shrd eax,edx,16
  112.     add ecx,eax
  113.     mov eax,[ZTemp]
  114.     imul [dword ebx+9*4]
  115.     shrd eax,edx,16
  116.     add ecx,eax
  117.     add ecx,[ebx+13*4]
  118.     mov [NewY],ecx
  119.     
  120.     mov eax,[XTemp]                   ;calc NewZ
  121.     imul [dword ebx+2*4]                          
  122.     shrd eax,edx,16
  123.     mov ecx,eax                       
  124.     mov eax,[YTemp]
  125.     imul [dword ebx+6*4]
  126.     shrd eax,edx,16
  127.     add ecx,eax
  128.     mov eax,[ZTemp]
  129.     imul [dword ebx+10*4]
  130.     shrd eax,edx,16
  131.     add ecx,eax
  132.     add ecx,[ebx+14*4]
  133.  
  134.     mov eax,[NewX]                    ;Projection X*D/Z
  135.     shl eax,DISTANCE
  136.     xor edx,edx                       ;clear high dword.
  137.     cdq
  138.     idiv ecx
  139.     adc ax,1
  140.     add ax,160                        ;adjust to screen center
  141.     or ax,ax
  142.     jns noxclip0
  143.     xor ax,ax
  144. noxclip0:
  145.     cmp ax,320
  146.     jl noxcliphi
  147.     mov ax,319
  148. noxcliphi:
  149.     stosw                             ;store it.
  150.     
  151.     mov eax,[NewY]                    ;Projection Y*D/Z
  152.     shl eax,DISTANCE
  153.     xor edx,edx
  154.     cdq
  155.     idiv ecx
  156.     adc ax,1
  157.     neg ax
  158.     add ax,100                        ;adjust to screen center.
  159.     or ax,ax
  160.     jns noyclip0
  161.     xor ax,ax
  162. noyclip0:
  163.     cmp ax,200
  164.     jl noycliphi
  165.     mov ax,199
  166. noycliphi:
  167.     stosw                             ;store it.
  168.     
  169.     pop cx
  170.     dec cx
  171.     jnz _XformPts
  172.     ret
  173.  
  174. ;Sin/Cos
  175. ; determines sin or cos of angle in ax (0..511)
  176. ; returns EDX = 32 bit angle.
  177. ; I was lazy enough to generate a 2k sin table to keep from determining
  178. ; signs, so this function is very simple.
  179. ; ax is preserved on Sines but killed on Cos's cuz I'm still lazy.  It
  180. ; doesn't matter tho since Sin is calculated before Cos.
  181. _Cos:    
  182.     add ax,128                       ;sin (T+90)
  183. _Sin:
  184.     push ax esi
  185.     and eax,511                      ;take care of big numbers.
  186.     shl ax,2
  187.     mov esi,offset sintab
  188.     add esi,eax
  189.     mov edx,[esi]
  190.     pop esi ax
  191.     ret             
  192.  
  193. proc _DotProduct
  194. ;Returns the cos of the angle between the two unit vectors.
  195. ;ESI -> Vector 1
  196. ;EBX -> Vector 2
  197. ;Out : ECX = Cos theta 0..1
  198.     lodsd
  199.     imul [dword ebx]
  200.     shrd eax,edx,16
  201.     mov ecx,eax
  202.     lodsd 
  203.     imul [dword ebx+4]
  204.     shrd eax,edx,16
  205.     add ecx,eax
  206.     lodsd
  207.     imul [dword ebx+8]
  208.     shrd eax,edx,16
  209.     add ecx,eax
  210.     ret
  211. endp
  212.  
  213. ends
  214. end                                        
  215.